Returns or sets a String that represents the name of the attached data source. Read/write.
expression.DataSource
expression Required. An expression that returns one of the objects in the Applies To list.
The following example sets the name of the data source if the name is blank.
Sub SetAndReturnDataSourceName()
Dim appOffice As OfficeDataSourceObject
Set appOffice = Application.OfficeDataSourceObject
With appOffice
.Open bstrConnect:="DRIVER=SQL Server;SERVER=ServerName;" & _
"UID=user;PWD=;DATABASE=Northwind", bstrTable:="Employees"
If .DataSource = "" Then
.DataSource = "Northwind"
MsgBox .DataSource
End If
End With
End Sub